import 'package:flutter/material.dart';
import 'package:bloc_arch/WXpage.dart';
import 'package:bloc_arch/TxlPage.dart';
import 'package:bloc_arch/FxPage.dart';
import 'package:bloc_arch/WoPage.dart';
//main方法，程序入口，runApp方法将根控件显示在屏幕上
void main() => runApp(Center(child: MyApp()));
//区别于原生开发的控件，布局等概念，flutter中所有的对象都是Widget，Widget分为
//StatelessWidget和StatefulWidget,区别请查看文档
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {//继承StatelessWidget，覆盖build方法，返回HomePage，也就是主页面
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  HomePageState createState() {
    return new HomePageState();
  }
}

class HomePageState extends State<HomePage> {

    var _bodys;
    int _tabIndex = 0;

    @override
    void initState() {//页面初始化状态时调用
      super.initState();
    }

    @override
    void dispose() {//页面控件被回收时调用
        super.dispose();
      }

    @override
    Widget build(BuildContext context) {//构建页面时调用，是页面的布局、控件

      _bodys = [
        new WXPage(),// lib/page/WXPage
        new TxlPage(),// lib/page/TxlPage
        new FxPage(),// lib/page/FxPage
        new WoPage(),// lib/page/WoPage
      ];

      return Scaffold(//Scaffold控件最重要
          body: _bodys[_tabIndex],//页面切换
          bottomNavigationBar: BottomNavigationBar(//底部导航
            items:<BottomNavigationBarItem>[//底部导航的items
              //icon图标  title文字   icon：Image控件 title:Text控件
              new BottomNavigationBarItem(icon: Image.asset("lib/timg.jpg",height: 40,width: 40,),title: Text("微信")),
              new BottomNavigationBarItem(icon: Image.asset("lib/timg.jpg",height: 40,width: 40,),title: Text("通讯录")),
              new BottomNavigationBarItem(icon: Image.asset("lib/timg.jpg",height: 40,width: 40,),title: Text("发现")),
              new BottomNavigationBarItem(icon: Image.asset("lib/timg.jpg",height: 40,width: 40,),title: Text("我")),
            ],
            type:  BottomNavigationBarType.fixed,//选中状态
            fixedColor: Colors.green,//选中时文字变成绿色
            currentIndex: _tabIndex,//当前页面标签
            onTap: (index) {//点击切换页面
              setState(() {
                _tabIndex = index;
              });
            },
          ),
          floatingActionButton: FloatingActionButton(onPressed: null),//悬浮按钮，点击事件设置为空
          drawer: Drawer(),
        );

  }

}
